﻿using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Xml.Serialization;

namespace Sanelib.CodeMaker
{
    public class DatabaseTableSchema
    {
        public string TableName { get; set; }
        public string Description { get; set; }
        public bool IsAudited { get; set; }

        private List<DatabaseTableColumnSchema> _columns;

        [XmlElement("Columns", typeof(DatabaseTableColumnSchema))]
        public DatabaseTableColumnSchema[] ColumnCollection
        {
            get
            {
                return Columns.ToArray();
            }
            set
            {
                if (value == null) return;
                _columns = new List<DatabaseTableColumnSchema>(value);
            }
        }

        [XmlIgnore]
        public List<DatabaseTableColumnSchema> Columns
        {
            get { return _columns ?? (_columns = new List<DatabaseTableColumnSchema>()); }
            set { _columns = value; }
        }

        public string GetTableAlias()
        {
            var regex = new Regex("[^A-Z]");
            var output = regex.Replace(TableName, "");
            return output;
        }
    }
}
